﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Maticsoft.Model;
namespace Maticsoft.BLL
{
	/// <summary>
	/// keyinfo
	/// </summary>
	public partial class keyinfo
	{
		private readonly Maticsoft.DAL.keyinfo dal=new Maticsoft.DAL.keyinfo();
		public keyinfo()
		{}
        public bool DeleteListstu(string keyInfoIdlist)
        {
            return dal.DeleteListstu(keyInfoIdlist);
        }
        public bool Existsbystuid(int stuid, int type)
        {
            return dal.Existsbystuid(stuid, type);
        }
        public DataSet GetList(int stuid, int type)
        {
            DataSet ds=new DataSet();
            if(type==1)
            ds=dal.GetList1(stuid);
            if (type == 2)
                ds = dal.GetList2(stuid);
            if (type == 3)
                ds = dal.GetList3(stuid);
            return ds;
        }
          /// <summary>
        /// 根据条件除数据
        /// </summary>
        public bool DeleteByWhere(string where)
        {
            return dal.DeleteByWhere(where);
        }
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int keyInfoId)
		{
			return dal.Exists(keyInfoId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Maticsoft.Model.keyinfo model)
		{
            //bool r = false;
            if (dal.Exists(model))
            {
                if (dal.Update(model) == true)
                    return 1;
                else
                    return 0;
            }
            else
            {

               return dal.Add(model);
            }
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.keyinfo model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int keyInfoId)
		{
			
			return dal.Delete(keyInfoId);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string keyInfoIdlist )
		{
			return dal.DeleteList(keyInfoIdlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.keyinfo GetModel(int keyInfoId)
		{
			
			return dal.GetModel(keyInfoId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Maticsoft.Model.keyinfo GetModelByCache(int keyInfoId)
		{
			
			string CacheKey = "keyinfoModel-" + keyInfoId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(keyInfoId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Maticsoft.Model.keyinfo)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.keyinfo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.keyinfo> DataTableToList(DataTable dt)
		{
			List<Maticsoft.Model.keyinfo> modelList = new List<Maticsoft.Model.keyinfo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Maticsoft.Model.keyinfo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Maticsoft.Model.keyinfo();
					if(dt.Rows[n]["keyInfoId"]!=null && dt.Rows[n]["keyInfoId"].ToString()!="")
					{
						model.keyInfoId=int.Parse(dt.Rows[n]["keyInfoId"].ToString());
					}
					if(dt.Rows[n]["stuId"]!=null && dt.Rows[n]["stuId"].ToString()!="")
					{
						model.stuId=int.Parse(dt.Rows[n]["stuId"].ToString());
					}
					if(dt.Rows[n]["tid"]!=null && dt.Rows[n]["tid"].ToString()!="")
					{
						model.tid=int.Parse(dt.Rows[n]["tid"].ToString());
					}
					if(dt.Rows[n]["answer"]!=null && dt.Rows[n]["answer"].ToString()!="")
					{
					model.answer=dt.Rows[n]["answer"].ToString();
					}
					if(dt.Rows[n]["fjurl"]!=null && dt.Rows[n]["fjurl"].ToString()!="")
					{
					model.fjurl=dt.Rows[n]["fjurl"].ToString();
					}
					if(dt.Rows[n]["type"]!=null && dt.Rows[n]["type"].ToString()!="")
					{
						model.type=int.Parse(dt.Rows[n]["type"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

